/*
 * File name:  PMIPActivit.java
 * Copyright:  Copyright (c) 2006-2013 hoperun Inc,  All rights reserved
 * Description:  <描述>
 * Author:  ren_qiujing
 * Last modified date:  2013-9-12
 * Version:  <版本编号>
 * Edit history:  <修改内容><修改人>
 */
package com.hoperun.product.base;

import com.hoperun.product.view.TipsDialogFragment;
import com.hoperun.product.view.WaitDialog;
import com.hoperun.yieldmgryue.R;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

/**
 * <一句话功能简述>
 * 
 * @Description<功能详细描述>
 * 
 * @author ren_qiujing
 * @Version [版本号, 2013-9-12]
 */
public abstract class MIP_BaseActivity extends AppCompatActivity {
	private WaitDialog mWaitDialog;

	protected String TAG = "";

//	public boolean isActivityDestroyed() {
//		return isActivityDestroyed;
//	}
//
//	public void setActivityDestroyed(boolean isActivityDestroyed) {
//		this.isActivityDestroyed = isActivityDestroyed;
//	}
//
//	protected boolean isActivityDestroyed = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		// requestWindowFeature(Window.FEATURE_NO_TITLE);
		TAG = this.getClass().getName();
		// 设置界面无标题
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		// 设置界面常亮
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
				WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
		 mWaitDialog = new WaitDialog(this);
		super.onCreate(savedInstanceState);

	}

	/**
	 * 显示加载圈圈...
	 */
	public void showWait() {
		mWaitDialog.show();
	}

	/**
	 * 停掉加载圈圈...
	 */
	public void stopWait() {
		mWaitDialog.dismiss();
	}

	public void toast(String msg) {
		Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub

		super.onStart();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		//isActivityDestroyed = true;
		super.onDestroy();
	}

	protected Handler mMIPHandler = new Handler() {

		/*
		 * (non-Javadoc)
		 * 
		 * @see android.os.Handler#handleMessage(android.os.Message)
		 */
		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			int requestType = msg.what;
			int errorCode = msg.arg1;

			Object retObj = msg.obj;
			try {
				if (errorCode == 0) {

					onPostHandle(requestType, retObj, true);

				} else {
					onPostHandle(requestType, retObj, false);
				}
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			super.handleMessage(msg);
		}

	};

	abstract public void onPostHandle(int requestType, Object objBody,
			boolean error) throws Exception;

}
